import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
class User {
    public String username ;
    public String password;
}

@WebServlet("/json")
public class jsonservlet extends HttpServlet {

    // 通过这个对象,就可以把json字符串解析成java对象,也可以将一个java对象解析成json对象
    private ObjectMapper objectMapper = new ObjectMapper();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // super.doPost(req, resp);
        User user = objectMapper.readValue(req.getInputStream(),User.class);
        resp.getWriter().write( user.username+user.password);
        System.out.println("hello");

    }
}
